import { createStore } from "vuex";
import { cartQueryAll } from "@/api/shoppingCart/shoppingCart.js";
const store = createStore({
	state: {
		token: "",
		userInfo: {},
		hasLogin: false,
		// shoppingList: uni.getStorageSync("shoppingList")
	},
	mutations: {
		login(state, provider) {
			state.hasLogin = true;
			state.userInfo = provider.userInfo;
			uni.setStorageSync('userInformation',provider)
			if (provider.token) {
				state.token = provider.userInfo.token;
				uni.setStorageSync('token', provider.userInfo.token)
			}
		},
		logout(state) { // 退出登录
			state.hasLogin = false;
			state.userInfo = {};
			state.token = "";
			// uni.clearStorage();
			uni.removeStorage({
				key: "token"
			});
			uni.removeStorage({
				key: "userInformation"
			});
		},
		// getShoppingList(state, provider) {
		// 	state.shoppingList = provider;
		// 	uni.setStorageSync("shoppingList", provider);
		// }
	},
	actions: {
		// async handleGetCartData({ commit }) {
		// 	const res = await cartQueryAll();
		// 	let data = res.data || [];
		// 	if (res.data && res.data.length) {
		// 		data.forEach(item => {
		// 			item.checked = false
		// 		})
		// 	}
		// 	commit("getShoppingList", data);
		// }
	},
	getters: {
		// getGoodsNum(state) {
		// 	return state.shoppingList.length || 0;
		// }
	}
})
 
export default store